package com.aaa.hospital.nurse.controller;

import com.aaa.hospital.ManagementEnd.pojo.User;
import com.aaa.hospital.nurse.service.OpenService;
import com.aaa.hospital.nurse.util.OpenDB;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.websocket.server.PathParam;
import java.util.List;

@Controller
@RequestMapping("/open")
public class OpenController {
    @Autowired
    private OpenService openService;
    @RequestMapping("/queryOpenDB")
    @ResponseBody
    public String queryOpenDB(){
        JSONObject json = new JSONObject();
        List<OpenDB> data = openService.queryOpenDB();;
        Object objData=JSONObject.toJSON(data);
        json.put("code", 0);
        json.put("msg", "");
        json.put("count",data.size());
        json.put("data",objData);
        return json.toJSONString();
    }


    @RequestMapping("/selectOpenDB")
    @ResponseBody
    public OpenDB selectOpenDB(@PathParam("warid") Integer warid){
        OpenDB data = openService.selectOpenDB(warid);;
        return data;
    }
    @RequestMapping("/updateStatus")
    @ResponseBody
    public int updateStatus(@PathParam("warid")Integer warid){
        OpenDB openDB = openService.selectOpenDB(warid);
        int result = openService.updateStatus(openDB.getWarid());
        if (result >0) {
            return openService.updateBedStatus(openDB.getId());
        }
        return 0;
    }


    @RequestMapping("/queryOpenDBByName")
    @ResponseBody
    public String queryOpenDBByName(String uname){
        JSONObject json = new JSONObject();
        List<OpenDB> data = openService.queryOpenDBByName(uname);
        Object objData=JSONObject.toJSON(data);
        json.put("code", 0);
        json.put("msg", "");
        json.put("count",data.size());
        json.put("data",objData);
        return json.toJSONString();
    }
}
